package org.teachertools.services;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;
import org.teachertools.common.ValidationUtils;
import org.teachertools.data.Categorie;

@Repository
public class CategorieService extends GenericService<Categorie> {

	@Override
	protected Class<Categorie> getObjectClass() {
		return Categorie.class;
	}

	@Override
	protected Query getSearchQuery(Categorie categorie) {
		StringBuffer request = new StringBuffer();
		request.append(" from Categorie entity where 1 = 1");
		if (ValidationUtils.isNotEmpty(categorie.getNom())) {
			request.append(" and upper(entity.nom) like upper(:label_1)");
		}
		Query query = entityManager.createQuery(request.toString());
		if (ValidationUtils.isNotEmpty(categorie.getNom())) {
			query.setParameter("label_1", prepareQueryParam(categorie.getNom()));
		}
		return query;
	}
}
